﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Cloak.Globalization;
using Cloak.Linq;

namespace Ruleweaver.Rules
{
	internal sealed class ConvertRuleToLambdaExpression : RuleVisitor
	{
	  internal LambdaExpression ConvertToLambdaExpression(Rule rule, Type targetType)
	  {
			throw new NotImplementedException();
	  }

		#region Overrides : RuleVisitor

		protected override Rule VisitCheck(CheckRule checkRule)
		{
			//var checkThatCall = Expression.Call(typeof(Check), "That", new[] { _target.Type }, _target);

			//var arguments = new[] { checkThatCall }.Union(checkRule.CheckArguments.ToConstants());

			//_body = Expression.Call(checkRule.Method, arguments);

			return checkRule;
		}

		protected override Rule VisitFixed(FixedRule fixedRule)
		{
			return fixedRule;
		}

		protected override Rule VisitComposite(CompositeRule compositeRule)
		{
			// An empty composite rule has no effect

			//if(compositeRule.Rules.Any())
			//{
			//  Expression expression = null;

			//  foreach(var rule in compositeRule.Rules)
			//  {
			//    Visit(rule);

			//    expression = expression == null ? _body : AppendBodyTo(expression, compositeRule.Type);
			//  }

			//  _body = expression;
			//}

			return compositeRule;
		}

		protected override Rule VisitMember(MemberRule memberRule)
		{
			//var priorTarget = _target;

			//_target = Expression.MakeMemberAccess(_target, memberRule.Member);

			//Visit(memberRule.Rule);

			//_target = priorTarget;

			return memberRule;
		}

		protected override Rule VisitNot(NotRule notRule)
		{
			//Visit(notRule.Rule);

			//_body = Expression.Not(_body);

			return notRule;
		}
		#endregion
	}
}